package com.cade.agriculturemall.utils;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Created by Lobby on 2017/11/30.
 */

public class ModelUtil {
    public static void initObject(Object object){
        Class clazz = object.getClass();
        Field[] fields = clazz.getDeclaredFields();
        try {
            Method method = clazz.getDeclaredMethod("getString", String.class);
            for (Field field : fields){
                field.setAccessible(true);
                field.set(object, method.invoke(object, field.getName()));
            }
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

    }

}
